﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace MultiApp.UserControls
{
    public sealed partial class CalculatorControl : UserControl
    {
        string act;
        double val1;
        double val2;


        public CalculatorControl()
        {
            this.InitializeComponent();
            
        }

        private void btnPlus_Click(object sender, RoutedEventArgs e)
        {
            
                val1 = Convert.ToDouble(txtInput.Text);
                txtInput.Text = "";
            lblOperator.Text = "+";
            act = "plus";
        }

        private void btnMinus_Click(object sender, RoutedEventArgs e)
        {
            
                val1 = Convert.ToDouble(txtInput.Text);
                txtInput.Text = "";
                lblOperator.Text = "-";
                act = "minus";
        }

        private void btnTimes_Click(object sender, RoutedEventArgs e)
        {
            
                val1 = Convert.ToDouble(txtInput.Text);

                txtInput.Text = "";
                lblOperator.Text = "*";
          
            act = "multiply";
        }

        private void btnSquare_Click(object sender, RoutedEventArgs e)
        {



                txtInput.Text = Math.Sqrt(Convert.ToDouble(txtInput.Text)).ToString();
        }

        private void btnDivide_Click(object sender, RoutedEventArgs e)
        {
            lblOperator.Text = "/";
                val1 = Convert.ToDouble(txtInput.Text);
            txtInput.Text = "";
          
           
            
            act = "divide";
        }

        private void btnEnter_Click(object sender, RoutedEventArgs e)
        {
            lblOperator.Text = "";
            val2 = Convert.ToDouble(txtInput.Text);
            switch (act)
            {
                case "plus":
                    txtInput.Text = (val1 + val2).ToString();
                    break;
                case "minus":
                    txtInput.Text = (val1 - val2).ToString();
                    break;
                case "multiply":
                    txtInput.Text = (val1*val2).ToString();
                    break;
                case "square":
                    txtInput.Text = Math.Sqrt(val1).ToString();
                    break;
                case "divide":
                    txtInput.Text = (val1/val2).ToString();
                    break;
            }
        }

        private void btnZero_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "0";
        }

        private void btnOne_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "1";
        }

        private void btnTwo_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "2";

        }

        private void btnThree_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "3";
        }

        private void btnFour_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "4";
        }

        private void btnFive_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "5";
        }

        private void btnSix_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "6";
        }

        private void btnSeven_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "7";
        }

        private void btnEight_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "8";
        }

        private void btnNine_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = txtInput.Text + "9";
        }

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            txtInput.Text = "";
            val1 = 0.0;
            val2 = 0.0;
            act = "";
        }
    }
}
